<template xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div class="content">
      <!-- 头部 -->
    <div class="main-title">
      <ul>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            首页
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            招聘管理
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div class="main-title-left main-title-select">
            发布信息
          </div>
          <div class="main-title-right">
            <!-- / -->
          </div>
        </li>
      </ul>
    </div>
    <div class="content-center" v-loading="opLoading">
      <div class="main-list">
        <div class="list-two">
          <div class="list-two-list">
            <div>职位</div>
            <div>
              <select @change="selectTypesClick" v-model="postype">
                <option v-for="(type,index) in postypes" v-bind:value="index" :key="index">{{type.name}}</option>
              </select>        
            </div>
          </div>
          <div class="list-two-list">
            <div>学历</div>
            <div>
              <select @change="selectTypesClick" v-model="educationtype">
                <option v-for="(type,index) in educationtypes" v-bind:value="index" :key="index">{{type.name}}</option>
              </select>             
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>招聘人数</div>
            <div>
              <input type="text" v-model="cntVal">                    
            </div>
          </div>
          <div class="list-two-list">
            <div>招聘状态</div>
            <div>
              <select @change="selectTypesClick" v-model="statetype">
                <option v-for="(type,index) in statetypes" v-bind:value="index" :key="index">{{type.name}}</option>
              </select>             
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-two">
            <div>经验</div>
            <div>
              <input type="text" placeholder="最低年限" v-model="workYearStartVal">             
            </div>
            <div>
             &nbsp;&nbsp;&nbsp; --
            </div>
            <div class="priceList">
              <input type="text" placeholder="最高年限" v-model="workYearEndVal">             
            </div>
            <div> 
              &nbsp;&nbsp;&nbsp;年
            </div>
          </div>
          <div>
            <div></div>
            <div>
                         
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-two">
            <div>薪资</div>
            <div>
              <input type="text" placeholder="最低薪资" v-model="priceMinVal">             
            </div>
            <div>
              &nbsp;&nbsp;&nbsp; --
            </div>
            <div class="priceList">
              <input type="text" placeholder="最高薪资" v-model="priceMaxVal">             
            </div>
            <div> 
              &nbsp;&nbsp;&nbsp;元
            </div>
          </div>
          <div>
            <div></div>
            <div>
                      
            </div>
          </div>
        </div>
        <div class="list-text">
          <div>详细介绍</div>
          <div>
            <textarea v-model="remakrVal"></textarea>                
          </div>
        </div>
        <div class="list-button">
          <div class="button-save" @click="addClick">
            发&nbsp;&nbsp;布
          </div>
          <div class="button-cancel" @click="blckClick">
            取&nbsp;&nbsp;消
          </div>
        </div>
      </div>
      <div :class="{showdel:isShowdel}" class="delPopup">
        <transition name="slide-fade">
          <div class="delContent">
            <v-mIntercept @ok="confirmClick" @canle="cancelClick" :name="titlename"></v-mIntercept>
          </div>
        </transition>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import mIntercept from "../module/mIntercept";
export default {
  components: {
    "v-mIntercept": mIntercept
  },
  data() {
    return {
      opLoading: false,
      type: "0",
      types: [{ name: "全部标签" }, { name: "标签1" }],
      statetype: "0",
      statetypes: [
        { name: "正常", index: 1 },
        { name: "急招", index: 2 },
        { name: "已完成", index: 4 },
        { name: "终止招聘", index: 8 }
      ],
      istype: "0",
      istypes: [{ name: "否" }, { name: "是" }],
      postype: "0",
      postypes: [],
      channeltype: "0",
      channeltypes: [],
      educationtype: "0",
      educationtypes: [
        { name: "无学历", inde: 1 },
        { name: "初中", inde: 2 },
        { name: "职高", inde: 4 },
        { name: "中专", inde: 8 },
        { name: "技校", inde: 16 },
        { name: "高中", inde: 32 },
        { name: "大专", inde: 64 },
        { name: "本科", inde: 128 },
        { name: "硕士", inde: 256 },
        { name: "博士", inde: 512 },
        { name: "三本", inde: 1024 },
        { name: "二本", inde: 2048 },
        { name: "一本", inde: 4096 },
        { name: "211", inde: 8192 },
        { name: "985", inde: 16384 }
      ],
      isShowdel: true,
      intercept: false,
      toPath: "",
      titlename: "劳动成果还未保存，是否退出？",
      cntVal: "",
      workYearStartVal: "",
      workYearEndVal: "",
      priceMinVal: "",
      priceMaxVal: "",
      remakrVal: "",
      addObj: {}
    };
  },
  // 过滤
  filters: {
    timeFun: function(val) {
      var now = new Date(val);
      var year = now.getYear() - 100;
      var month = now.getMonth() + 1;
      month = month > 9 ? month : "0 " + month;
      var date = now.getDate();
      date = date > 9 ? date : "0 " + date;
      var hour = now.getHours();
      hour = hour > 9 ? hour : "0 " + hour;
      var minute = now.getMinutes();
      minute = minute > 9 ? minute : "0 " + minute;
      return (
        "20 " + year + "- " + month + "- " + date + " " + hour + ": " + minute
      );
    }
  },
  // 模块新建时
  created: function() {
    var self = this;
    self.channeltypes = JSON.parse(sessionStorage.getItem("sourcestr"));
    self.postypes = JSON.parse(sessionStorage.getItem("poststr"));
    if (self.$route.query.op == 2) {
      var requirementsObj = JSON.parse(
        sessionStorage.getItem("requirementsListObj")
      );
      self.workYearStartVal = requirementsObj.workYearStart;
      self.cntVal = requirementsObj.cnt;
      self.workYearEndVal = requirementsObj.workYearEnd;
      self.priceMinVal = requirementsObj.priceMin;
      self.priceMaxVal = requirementsObj.priceMax;
      self.remakrVal = requirementsObj.remakr;
      self.educationtypes.forEach(function(ele, ind) {
        if (ele.inde == requirementsObj.education) {
          self.educationtype = ind;
        }
      });
      self.postypes.forEach(function(ele, ind) {
        if (ele.value == requirementsObj.position) {
          self.postype = ind;
        }
      });
    }
  },
  // 计算属性
  mounted() {},
  // 事件处理
  methods: {
    // 返回
    navBackClick(index) {
      if (index == 2) {
        this.$router.push({
          path: "/home/requirements"
        });
      } else if (index == 1) {
        this.$router.push({
          path: "/home/requirements"
        });
      }
    },
    // 返回
    blckClick() {
      this.$router.push({
        path: "/home/requirements"
      });
    },
    // 新增
    addClick() {
      var self = this;
      self.addObj["position"] = self.postypes[self.postype].value;
      self.addObj["education"] = self.educationtypes[self.educationtype].inde;
      self.addObj["status"] = self.statetypes[self.statetype].index;
      var vFunFalse = self.vFun();
      if (self.$route.query.op == 2) {
        self.addObj["id"] = self.$route.query.id;
      }
      if (vFunFalse == true) {
        self.opLoading = true;
        self
          .getadvertisesPlan(self.addObj)
          .then(data => {
            self.opLoading = false;
            if (data.code == 200) {
              self.$router.push({
                path: "/home/requirements"
              });
            } else {
              self.$message({
                type: "info",
                message: data.message
              });
            }
          })
          .catch(msg => {
            self.opLoading = false;
            this.$router.push({
              path: "/login"
            });
          });
      }
    },
    vFun() {
      var self = this;
      var phoneReg = new RegExp(/^\d{11}$/);
      var numReg = new RegExp(/^\d{1,7}$/);
      var num1Reg = new RegExp(/^\d{1,7}$/);
      var emailReg = new RegExp(
        /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
      );
      var strReg = new RegExp(/^[\u4e00-\u9fa5]{2,10}$/);
      var vFunFalse = false;
      if (self.cntVal) {
        if (numReg.test(self.cntVal * 1) == true) {
          self.addObj["cnt"] = self.cntVal * 1;
          if (self.workYearStartVal) {
            if (numReg.test(self.workYearStartVal * 1) == true) {
              self.addObj["workYearStart"] = self.workYearStartVal * 1;
              if (self.workYearEndVal) {
                if (numReg.test(self.workYearEndVal * 1) == true) {
                  self.addObj["workYearEnd"] = self.workYearEndVal * 1;
                  if (self.workYearEndVal * 1 <= self.workYearStartVal * 1) {
                    vFunFalse = false;
                    self.$message({
                      type: "info",
                      message: "最高年限必须大于最低年限"
                    });
                  } else {
                    if (self.priceMinVal) {
                      if (numReg.test(self.priceMinVal * 1) == true) {
                        self.addObj["priceMin"] = self.priceMinVal * 1;
                        if (self.priceMaxVal) {
                          if (num1Reg.test(self.priceMaxVal * 1) == true) {
                            self.addObj["priceMax"] = self.priceMaxVal * 1;
                            if (self.priceMaxVal * 1 <= self.priceMinVal * 1) {
                              vFunFalse = false;
                              self.$message({
                                type: "info",
                                message: "最高薪资必须大于最低薪资"
                              });
                            } else {
                              vFunFalse = true;
                            }
                          } else {
                            self.$message({
                              type: "info",
                              message: "最高薪资项必填且为数字"
                            });
                            vFunFalse = false;
                          }
                        } else {
                          self.$message({
                            type: "info",
                            message: "最高薪资项必填且为数字"
                          });
                          delete self.addObj.priceMax;
                        }
                      } else {
                        self.$message({
                          type: "info",
                          message: "最低薪资项必填且为数字"
                        });
                        vFunFalse = false;
                      }
                    } else {
                      self.$message({
                        type: "info",
                        message: "最低薪资项必填且为数字"
                      });
                      delete self.addObj.priceMin;
                    }
                  }
                } else {
                  self.$message({
                    type: "info",
                    message: "最高年限项必填且为数字"
                  });
                  vFunFalse = false;
                }
              } else {
                self.$message({
                  type: "info",
                  message: "最高年限项必填且为数字"
                });
                delete self.addObj.workYearEnd;
              }
            } else {
              self.$message({
                type: "info",
                message: "最低年限项必填且为数字"
              });
              vFunFalse = false;
            }
          } else {
            self.$message({
              type: "info",
              message: "最低年限项必填且为数字"
            });
            delete self.addObj.workYearStart;
          }
        } else {
          self.$message({
            type: "info",
            message: "招聘人数项必填且为数字"
          });
          vFunFalse = false;
        }
      } else {
        self.$message({
          type: "info",
          message: "招聘人数项必填且为数字"
        });
        delete self.addObj.cnt;
      }

      if (self.remakrVal) {
        self.addObj["remakr"] = self.remakrVal;
      } else {
        delete self.addObj.remakr;
      }
      return vFunFalse;
    },
    selectTypesClick() {},
    confirmClick() {
      this.intercept = true;
      var url = this.toPath;
      this.$router.push({
        path: url
      });
    },
    //取消未保存弹出框
    cancelClick() {
      this.isShowdel = true;
    },
    ...mapActions(["getadvertisesPlan"])
  },
  // 监视
  watch: {}
};
</script>
<style scoped>
.button-save {
  margin-left: 108px;
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}
.button-cancel {
  cursor: pointer;
  margin-left: 8px;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  background-color: #fff;
  color: rgba(0, 0, 0, 0.65);
}
.list-button {
  margin-top: 45px;
  width: 500px;
  display: flex;
}
.list-file-r-file label {
  border-radius: 4px;
  min-width: 120px;
  height: 30px;
  background-color: #2fa89e;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
.list-file-r-file label img {
  width: 20px;
  height: 20px;
}
.list-file-r-file input {
  opacity: 0;
}
.list-file-r-file {
  min-width: 110px;
  height: 28px;
  margin-left: 25px;
  display: flex;
}
.priceList {
  margin-left: 19px;
}
.list-file-r-img {
  width: 110px;
  height: 50px;
  border: 1px solid #ccc;
}
.list-file-right {
  width: 500px;
  height: 50px;
  margin-left: 15px;
  display: flex;
  align-items: center;
}
.list-file {
  display: flex;
  height: 70px;
  margin-top: 18px;
  width: 100%;
}

.list-file > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}

.list-text {
  display: flex;
  min-height: 32px;
  width: 100%;
  margin-top: 35px;
}

.list-text > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-text > div:nth-child(2) textarea {
  width: 80%;
  resize: none;
  height: 129px;
  border: 1px solid #ffd7d7d7;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
  padding-top: 7px;
  padding-left: 7px;
}
.list-text > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 110px);
  min-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-two {
  height: 32px;
  width: 100%;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}
.list-two-two > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-two > div:nth-child(2) {
  margin-left: 15px;
}
.list-two-list {
  display: flex;
  width: 50%;
  align-items: center;
}
.list-two-list > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-list > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 118px);
  /* border: 1px solid red; */
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-list > div:nth-child(2) input {
  width: 94%;
}
.list-two-list > div:nth-child(2) select {
  width: calc(94% + 7px);
}
.list-two > div:nth-child(2) {
  margin-left: 15px;
}

.list-two {
  display: flex;
  align-items: center;
  height: 32px;
  margin-top: 35px;
}

select {
  width: 207px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 3px;
  font-size: 14px;
}
input {
  width: 200px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 7px;
  font-size: 14px;
}
select::-ms-expand,
select::-webkit-expand {
  display: none;
}

.main-list > div {
  width: 100%;
  min-height: 32px;
}
.main-list {
  width: 100%;
  margin-top: 15px;
  background-color: #ffff;
  min-height: 720px;
}

.main-title-noSelect {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}
.main-title-select {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 600;
}

.main-title-right {
  width: 23px;
  text-align: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}

.main-title ul {
  width: 100%;
  display: flex;
  height: 54px;
  margin-left: 34px;
}
.main-title ul li {
  display: flex;
}
.main-title {
  width: 100%;
  height: 54px;
  background-color: #fff;
  line-height: 54px;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: inset 0px 3px 3px 0px #ccc;
}
.content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(240, 242, 245, 1) !important;
  min-height: 720px;
  /* border: 1px solid red; */
  display: flex;
  flex-wrap: wrap;
}

.content-center {
  overflow: hidden;
  width: calc(100% - 48px);
  margin-left: 24px;
  background-color: #fff;
  margin-top: 24px;
  border-radius: 3px;
  min-height: calc(100% - 78px - 24px);
  margin-bottom: 24px;
}
/*取消弹出框*/

.delPopup {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  z-index: 1000000;
}

.showdel {
  display: none;
}

.delContent {
  width: 525px;
  height: 280px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0px 10px 10px #eaeaea;
  border-radius: 7px;
  margin: calc((100vh - 280px) / 2) auto;
  z-index: 100000;
}

.slide-fade-enter-active {
  transition: all 0.7s ease;
}

.slide-fade-enter,
.slide-fade-leave-active {
  transform: translateY(-30px);
  opacity: 0;
}
</style>